package com.ease.util {

   import flash.external.ExternalInterface;

   import mx.controls.Alert;


   internal class MsieBrowserInfo implements IBrowserInfo {
      private var _name:String = BrowserUtil.BROWSER_MSIE;
      private var _version:String = null;
      private var _os:String = null;
      private var _arch:String = null;
      private var _cookieEnabled:Boolean = false;

      public function get version():String {
         return _version;
      }

      public function get name():String {
         return _name;
      }

      public function get os():String {
         return _os;
      }

      public function get arch():String {
         return _arch;
      }

      public function get cookieEnabled():Boolean {
         return _cookieEnabled;
      }

      /**
       * Examines the user agent string and populates as many of the
       * properties of this instance as possible from it as possible.
       * Returns whether this browser is supported.
       *
       * @param ua User agent string
       * @return true if this is a supported version of the browser, false otherwise
       */
      public function detect(ua:String):Boolean {
         //  1: Mozilla Version
         //  2: Product
         //  3: Version major number
         //  4: Version minor number(including leading decimal point)
         //  5: Provider*
         //  6: OS
         //  7: Extension
         //  8: Addition
         // See also:
         //   http://msdn.microsoft.com/en-us/library/dd371735(VS.85).aspx
         //   http://blogs.msdn.com/b/ie/archive/2009/01/09/the-internet-explorer-8-user-agent-string-updated-edition.aspx
         //   http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx
         var re:RegExp = /Mozilla\/(.*?) \(compatible; (MSIE) (\d)(.*?);? (.*?)?;? ?(.*?)*\) ?( .*?)?/i;

         var m:Array = re.exec(ua);

         if (m == null) {
            return false;
         }

         // If the provider isn't specified, then the OS will match early.
         if (m[7] && m[7].length > 0) {
            if (m[6].indexOf('.net') > -1 && m[7].indexOf('.net') > -1) {
               _os = m[5];
            } else {
               _os = m[6];
            }
         } else {
            _os = m[5];
         }
         _version = m[3] + m[4];

         _cookieEnabled = ExternalInterface.call("function() {return window.navigator.cookieEnabled;}");
         _arch = ExternalInterface.call("function() {return window.navigator.cpuClass;}");

         if (Number(m[3]) < 7) {
            return false;
         }

         return true;

      }
   }

}